<?php
/**
 * Created by PhpStorm.
 * Author: i@fedax.cn
 * Date: 2018/1/5
 * Time: 18:01
 */

namespace app\admin\controller;

use app\admin\model\DailyLog as DailyLogModel;
use app\admin\model\Admin;
/**
 * 日志记录
 * Class DailyLog
 * @package app\admin\controller
 */
class DailyLog extends Index
{
    /**
     * @return \think\response\View
     */
    public function index()
    {
        return view();
    }

    /**
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function indexData(){
        $dailyLogModel = new DailyLogModel();
        $page_config = array(
            'page' => input('post.offset', 1),
            'list_rows' => input('post.limit', 10),
        );
        $order = input('post.sort', 'id') . " " . input('post.order', 'desc');
        $where = array();//组装搜索语句
        $admin_name = input('admin_name');
        if($admin_name){
            $admin_user_id = Admin::where('admin_name','=',$admin_name)->value('id');
            $where[] = ['admin_id', '=', $admin_user_id];
        }
        if (input('type')) {
            $where[] = ['type', '=', input('type')];
        }
        if (input('start_time')) {
            $where[] = ['create_time', '>', (input('start_time'))];
        }
        if (input('end_time')) {
            $where[] = ['create_time', '<', (input('end_time'))];
        }
        $data = $dailyLogModel->getDataList($page_config, $where, $order);
        return json($data);
    }
}